package by.semerikov.statictic;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import by.semerikov.parts.Code;
import by.semerikov.parts.Log;

public class StaticticByCodePersents {
	private List<Log> list = new ArrayList<>();

	public List<Log> getList() {
		return list;
	}

	public void setList(List<Log> list) {
		this.list = list;
	}

	public StaticticByCodePersents(List<Log> list) {
		super();
		this.setList(list);
	}
	
	public Map<Integer,Double> getStaticticByCode()
	{
		Map<Integer,Double> result = new HashMap<Integer,Double>();
		Integer key;
		for (int i = 0; i < Code.codes.length; i++) {
			key = Code.codes[i];
			Integer count = 0;
			for (int j = 0; j < list.size(); j++) {
				if(key.equals( Code.codes[list.get(j).getCode().getCode()]))
				{
					count++;
				}
			}
			Double persent = ((1.0)*count)/list.size();
			result.put(key, persent);
		}
		return result;
	}

}
